package cdu.xjj.repository.service;

import cdu.xjj.pojo.entity.service.TestItemScore;
import cdu.xjj.pojo.vo.TestItemScoreInfoVO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;


public interface TestItemScoreRepository extends JpaRepository<TestItemScore, Long> {

    TestItemScore findByItemIdAndStudentId(Long itemId, Long studentId);


    @Query("SELECT NEW cdu.xjj.pojo.vo.TestItemScoreInfoVO(" +
            "s.id, i.name, s.itemId, i.unit, i.minValue, i.maxValue, i.genderLimit, i.isBouns, s.grade, s.score) " +
            "FROM TestItemScore s JOIN TestItem i ON s.itemId = i.id " +
            "WHERE s.studentId = :studentId")
    List<TestItemScoreInfoVO> findTestItemScoresByStudentId(@Param("studentId") Long studentId);


}